package com.winderinfo.yikaotianxia.ui.setup;

import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.winderinfo.yikaotianxia.R;
import com.winderinfo.yikaotianxia.core.api.Api;
import com.winderinfo.yikaotianxia.core.base.BaseActivity;
import com.winderinfo.yikaotianxia.core.mvp.Contract;
import com.winderinfo.yikaotianxia.core.mvp.Presenter;

import butterknife.BindView;
import butterknife.OnClick;

public class AboutUsActivity extends BaseActivity implements Contract.View {

    @BindView(R.id.ab_logourl)
    ImageView abLogourl;
    @BindView(R.id.ab_version)
    TextView abVersion;
    @BindView(R.id.ab_developers)
    TextView abDevelopers;
    @BindView(R.id.ab_website)
    TextView abWebsite;
    @BindView(R.id.ab_phone)
    TextView abPhone;
    @BindView(R.id.ab_email)
    TextView abEmail;
    @BindView(R.id.ab_wechat)
    TextView abWechat;
    private Presenter presenter;

    @Override
    protected int initLayoutId() {
        return R.layout.activity_aboutus;
    }

    @Override
    protected void initView() {
        //实例P
        presenter = new Presenter(this);
    }

    @Override
    protected void initData() {
        //请求关于我们
        presenter.onPostRequest(Api.ABOUTUS, null, AboutUsBean.class);
    }

    @Override
    public void onSuccess(Object data) {
        //关于我们数据
        if (data instanceof AboutUsBean) {
            Glide.with(this)
                    .load(((AboutUsBean) data).getAboutMe().getLogourl())
                    .apply(RequestOptions.bitmapTransform(new RoundedCorners(20)))//圆角半径
                    .into(abLogourl);
            abVersion.setText("版本信息：" + ((AboutUsBean) data).getAboutMe().getVersion());
            abDevelopers.setText("开发者：" + ((AboutUsBean) data).getAboutMe().getDevelopers());
            abWebsite.setText("官方网站：" + ((AboutUsBean) data).getAboutMe().getWebsite());
            abPhone.setText("客服热线：" + ((AboutUsBean) data).getAboutMe().getPhone());
            abEmail.setText("联系邮箱：" + ((AboutUsBean) data).getAboutMe().getEmail());
            abWechat.setText("官方微信：" + ((AboutUsBean) data).getAboutMe().getWechat());
        }
    }

    @Override
    public void onFailure(Object error) {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.onUntying();
    }


    @OnClick(R.id.ab_back)
    public void onViewClicked() {
        finish();
    }
}
